module.exports = (req, resp, next) => {
    req.sessionContext = {

    };
    if(req.body.Terminal) {
        req.body.terminal = req.body.Terminal;
    }
    // let token = req.headers['authorization'];
    // if (token) {
    //     let uws = credentials();
    //     let credential = uws.filter(uw => token == new Buffer(`${uw.username}!${uw.password}`).toString('base64'))[0];
    //     if (credential) {
    //         req.sessionContext.userId = credential.username;
    //     } else {
    //         throw {
    //             code: 403,
    //             message: 'session invalide or expired, please login again',
    //         }
    //     }
    // }
    next();
}

function credentials() {
    let c = global.config.Credentials;
    let pairs = c.split(',');
    return pairs.map(p => {
        let kv = p.split('@');
        return {
            username: kv[0],
            password: kv[1]
        }
    })
}